public class HashBucket2<K,V> {
    private static class Node<K,V>{
        public K key;
        public V val;
        public Node<K,V> next;
        public Node(K key,V val){
            this.key = key;
            this.val = val;
        }
    }
    public Node<K,V>[] array = (Node<K,V>[])new Node[10];
    private int usedSize;
    private static final double MAX_LOAD_FACTOR = 0.75;
    public void push(K key,V val) {
        int hashCode = key.hashCode();
        int index = hashCode % array.length;
        Node<K,V> cur = array[index];
        while(cur != null){
            if(cur.key.equals(key)){
                cur.val = val;
                return;
            }
            cur = cur.next;
        }
        Node<K,V> node = new Node<>(key,val);
        node.next = array[index];
        array[index] = node;
        usedSize++;
        if(doLoadFactor() >= MAX_LOAD_FACTOR){
            resize();
        }
    }

    private void resize() {
        Node<K,V>[] newArray = (Node<K, V>[]) new Node[array.length*2];
        for (int i = 0; i < array.length; i++) {
            Node<K,V> cur = array[i];
            while(cur != null){
                int hashCode = cur.key.hashCode();
                int index = hashCode % newArray.length;
                Node<K, V> curN = cur.next;
                cur.next = newArray[index];
                newArray[index] = cur;
                cur = curN;
            }
        }
        array = newArray;
    }

    private double doLoadFactor() {
        return usedSize*0.1 / array.length;
    }

    public V getVal(K key) {
        int hashCode = key.hashCode();
        int index = hashCode%array.length;
        Node<K,V> cur = array[index];
        while(cur != null){
            if(cur.key.equals(key)){
                return cur.val;
            }
            cur = cur.next;
        }
        return null;
    }
}
